package com.hao.netty.client;

import com.hao.netty.handler.ChatClientInitializer;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * TODO
 *
 * @author 97472
 * @version 1.0
 * @date 2021/12/7 17:36
 */
public class NewClient {
    private final static Integer SERVER_PORT = 6789;

    private final static String SERVER_IP = "127.0.0.1";

    public static void main(String[] args) {

        EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
        try {

            Bootstrap bootstrap = new Bootstrap();

            bootstrap.group(eventLoopGroup)
                    .channel(NioSocketChannel.class)
                    .handler(new ChatClientInitializer());

            ChannelFuture connectFuture = bootstrap.connect(SERVER_IP, SERVER_PORT).sync();

            Channel channel = connectFuture.channel();
            channel.writeAndFlush("fuck you");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            eventLoopGroup.shutdownGracefully();
        }
    }
}
